<?php defined('SYSPATH') or die('No direct script access.');

/**
 *
 * @author pahhan
 */
class Task_Parser_Update extends Minion_Task
{
    protected $_options = array(
        'id' => NULL,
        'last_external_id' => null,
    );

    public function build_validation(Validation $validation)
    {
        return parent::build_validation($validation)
            ->rule('id', 'not_empty') // Require this param
            ->rule('id', 'numeric'); // This param should be numeric
    }

    protected function _execute(array $params)
    {
        $id = $params['id'];
        $pi = ORM::factory('ParseInfo', $id);
        if( !$pi->id ) throw new Exception(sprintf('ParseInfo with id=%s not found', $id));

        if( !is_null($params['last_external_id']) )
            $pi->last_external_id = $params['last_external_id'];

        $pi->save();

        printf("Parser saved\n");
    }

}

